package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.Get24PointsBean;
import com.wenlin.myproduction.util.RegexUtils;
import com.wenlin.myproduction.util.TypeData;
import com.wenlin.myproduction.util.TypeDataNames;
import com.wenlin.myproduction.util.UI;

import org.greenrobot.eventbus.EventBus;

import me.drakeet.multitype.ItemViewBinder;

/**
 * @author 文琳
 * @Email 377979485@qq.com
 * @desc
 * @time 2022-12-21 星期三 21:20
 */
public class Get24PointsBinder extends ItemViewBinder<Get24PointsBean, Get24PointsBinder.VH> {


    @NonNull
    @Override
    protected VH onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new VH(inflater.inflate(R.layout.item_get_24_points, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull VH holder, @NonNull Get24PointsBean item) {
        UI.setText(holder.tvPosition, item.getPosition());
        StringBuilder str = new StringBuilder();
        for (int num :
                item.getList()) {
            str.append(num);
        }
        str.append("：");
        String strContent = RegexUtils.getFormatNum(item.getFirst()) + item.getFirstMethod() + RegexUtils.getFormatNum(item.getSecond()) + "=" + RegexUtils.getFormatNum(item.getResult1()) + "，" + RegexUtils.getFormatNum(item.getThird()) + item.getSecondMethod() + RegexUtils.getFormatNum(item.getFourth()) + "=" + RegexUtils.getFormatNum(item.getResult2()) + "，" + RegexUtils.getFormatNum(item.getFifth()) + item.getThirdMethod() + RegexUtils.getFormatNum(item.getSixth()) + "=" + RegexUtils.getFormatNum(item.getResult3());
        UI.setText(holder.tv, str + strContent);
        UI.setOnClickListener(holder.tvCopy, v -> EventBus.getDefault().post(new TypeData<>(TypeDataNames.clickCopyButton, str + strContent)));
    }

    static class VH extends RecyclerView.ViewHolder {
        TextView tvPosition, tv, tvCopy;

        public VH(@NonNull View itemView) {
            super(itemView);
            tvPosition = itemView.findViewById(R.id.tv_position);
            tv = itemView.findViewById(R.id.tv);
            tvCopy = itemView.findViewById(R.id.tv_copy);
        }
    }
}
